var myGrid;
fileType="history";
$(function() {
	myGrid = $("#list").jqGrid({
		url : "historyfileitem/history-file-item!datalist",
		datatype : "json",
		mtype : 'GET',
		colNames : ["选取", "文件名","下载", "保存日期", "操作人" ],
		colModel : [ {
			name : 'id',
			index : 'id',
			width : 50,
			formatter : selectFormatter

		}, {
			name : "title",
			index : "title",
			width : 300,
			formatter : titleFormatter
		},{
			name : "id",
			index : "id",
			width : 80,
			formatter : downFormatter
		}, {
			name : "lastDate",
			index : "lastDate",
			width : 150
		}, {
			name : "owner",
			index : "owner",
			width : 50,
			formatter : userFormatter
		} ],
		pager : '#pager',
		rowNum : 10,
		rowList : [ 10, 20, 30 ],
		sortname : 'title',
		sortorder : 'asc',
		viewrecords : true,
		caption : "历史文件",
		width : '750',
		height : '300',
		jsonReader : {
			repeatitems : false,
			id : "0"
		}
	});

	myGrid.jqGrid("navGrid", "#pager", {
		edit : false,
		add : false,
		del : false,
		search : false
	});
});
function selectFormatter(cv, opt, row) {
	var fid = row['id'];
	var title = row['title'];
	var link = $("<input type=\"checkbox\" onclick=\"checkFile('" + fid + "','" + title + "',this.checked);\"></input>");
	return $("<span></span>").append(link).html();

}
function userFormatter(v, opt, row) {
	return v ? v.localName : "-";
}
function titleFormatter(v, opt, row) {
	var id = row['id'];
	var link = $("<a href=\"javascript:opendoc('" + id + "');\">" + v + "</a>");
	return $("<p></p>").append(link).html();
}
function downFormatter(v,opt,row){
	var eid = v;
	var link = $("<a></a>");	
	link.attr("href", "historyfileitem/history-file-item!download?bean.id="+ eid);
	link.attr("target", "_blank");
	link.html("<b>下载</b>");
	return $("<span></span>").append(link).html();
}
function opendoc(id) {
	var url = "historyfileitem/history-file-item!get?mapDefaultActionMethod=false&bean.id="
			+ id;
	window.open(url, "historyfilewin");
}